﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_CM_GetLinkmenByClientAddmanID]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_CM_GetLinkmenByClientAddmanID];
GO
CREATE PROCEDURE [dbo].[sproc_CM_GetLinkmenByClientAddmanID]
@id int
/*-----------------------------------------------
功能：根据客户添加人id得到所有其添加的客户的联系人
参数：
    @id    客户添加人id

-------------------------------------------------*/
AS
    SELECT  UDS_CM_Linkman.ID,
        UDS_CM_Linkman.NAME AS NAME,
        UDS_CM_Linkman.Telephone,
        UDS_CM_Linkman.Mobile, 
        UDS_CM_Linkman.Email,
        (case UDS_CM_Linkman.Gender when 1 then '男' else '女' end) as SexName,
        UDS_CM_Linkman.Name as UnitName,
        UDS_CM_Linkman.Position,
        UDS_CM_Linkman.Address
        
    FROM UDS_CM_Linkman,UDS_CM_ClientInfo 
    WHERE UDS_CM_Linkman.ClientID=UDS_CM_ClientInfo.ID AND ClientID IN(
        SELECT ID FROM UDS_CM_ClientInfo WHERE AddManID=@ID)